<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui" xmlns="http://www.w3.org/1999/xhtml"
	xml:lang="en" lang="en"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
	<ui:composition template="/protegido/main.xhtml">
		<ui:define name='conteudoPrincipal'>
			<script type="text/javascript" charset="utf-8">
				$(document).ready(
						function() {
							$("#navigation li.matriculaAdm a").addClass(
									"active");
							$("#navigation li").parent().find('li')
									.removeClass("active");
							if ($("#matriculaAdm")) {
								$("#matriculasAdm").addClass("active");
							}

							$(".alunoMatriculas").find("div").hide().find(
									"div table").hide();
							$("a.matriculasAluno").click(
									function(event) {
										event.stopPropagation();
										var $target = $(event.target);
										if ($target.closest("td").hasClass(
												"alunoMatriculas")) {
											$target.slideUp(80);
										} else {
											$target.closest("tr").next().find(
													"div").slideToggle(70);
										}
										document.getElementById("matriculasForm").reset();  
									});
						});
			</script>

			<style type="text/css">
				#duas-colunas {
					magin-bottom: 50px;
					min-height: 50px;
				}

				#duas-colunas .esq {
					float: left;
				}

				#duas-colunas .dir {
					float: left;
					margin-left: 25px;
				}

				#duas-colunas .botao {
					float: left;
					margin-left: 25px;
					padding-top: 13px;
				}

				input {
					width: 180px;
				}
			</style>
			<h2>Matrículas Cadastradas</h2>

			<h:form id="matriculasForm" prependId="false">
				<div id="campos-busca">
					<div id="duas-colunas">
						<div class="esq">
							<label for="matricula">Matrícula do aluno:</label><br />
							<h:inputText type="text" name="nome" value="#{bMatriculaAluno}"
								id="matricula">
							</h:inputText>
						</div>
						<div class="dir">
							<label for="nome">Nome do Aluno:</label><br />
							<h:inputText type="text" name="nome" value="#{bNomeAluno}"
								id="nome">
							</h:inputText>
						</div>

						<div class="botao">
							<h:commandButton type="submit" name="buscar" class="submit"
								value="Buscar" id="buscar" update="@form" 
								oncomplete="return false;">
								<f:setPropertyActionListener
									target="#{matriculaMB.bMatriculaAluno}"
									value="#{bMatriculaAluno}" />
								<f:setPropertyActionListener target="#{matriculaMB.bNomeAluno}"
									value="#{bNomeAluno}" />
							</h:commandButton>
						</div>
					</div>
					<c:if
						test="#{matriculaMB.bMatriculaAluno !='' || matriculaMB.bNomeAluno !=''   }">
						<small style="font-size: 0.8em;">*Para listar tos os alunos com
							matrículas cadastradas, deixe em branco o campo matrícula e nome
							do aluno, em seguida, pressione botão buscar.</small>
					</c:if>
					<c:if
						test="#{matriculaMB.bMatriculaAluno == '' and matriculaMB.bNomeAluno == '' }">
						<small style="font-size: 0.8em;">*Todas os alunos com matriculas
							cadastradas estão sendo listadas.</small>
					</c:if>
					<br />
				</div>
			</h:form>
			<h:form prependId="false">
				<table border="0" cellpadding="0" cellspacing="0" width="100%"
					style="font-size: 12px;">
					<tbody>
						<tr class="even">
							<th scope="col">Matrícula do Aluno</th>
							<th scope="col">Nome</th>
							<th scope="col">Total de Matriculas</th>
							<th scope="col">Ações</th>
						</tr>
						<c:choose>
							<c:when test="#{matriculaMB.alunosMatriculas.size() > 0}">
								<c:forEach items="#{matriculaMB.alunosMatriculas}" var="a">
									<tr>
										<td scope="col">#{a.matricula}</td>
										<td scope="col">#{a.nome}</td>
										<td scope="col">#{a.matriculas.size()}</td>
										<td scope="col"><h:commandLink update="@form" ajax="false"
												title="Visualizar matrículas do aluno"
												class="matriculasAluno" onclick="return false;">
												
											</h:commandLink> 	
											<h:commandLink title="Matrícular aluno em disciplina" value=" "
												styleClass="novoButton" action="#{matriculaMB.novaMatricula(a.id)}"/>
										</td>
									</tr>
									<tr style="margin: 0; padding: 0;">
										<td class="alunoMatriculas" colspan="6"
											style="margin: 0; padding: 0;">
											<div>
											  
												<table
													style="background-color: rgba(255, 51, 0, 0.1); width: 100%;">
													<tr>
														<td style="font-weight: bold;">Disciplina</td>
														<td style="font-weight: bold;">Proressor</td>
														<td style="font-weight: bold;">Situação</td>
														<td style="font-weight: bold;">Ações</td>
													</tr>
													<c:forEach items="#{a.matriculas}" var="am">
														<h:inputHidden value="#{am.disciplina.nome}" />
														<tr>
															<td scope="col">#{am.disciplina.nome}</td>
															<td scope="col">#{am.disciplina.professor.nome}</td>
															<td scope="col">#{am.situacao}</td>
															<td scope="col"><h:commandLink value=" "
																	title="Editar" styleClass="editButton"
																	action="#{matriculaMB.editarMatricula(am.id)}" /> <h:commandLink
																	value=" " title="Deletar" styleClass="removeButton"
																	action="#{matriculaMB.doExcluir(am.id)}" /></td>
														</tr>
													</c:forEach>
												</table>
												
											</div>
										</td>
									</tr>
								</c:forEach>
							</c:when>
							<c:otherwise>
								<br />
								<tr>
									<td colspan="6">Nenhum aluno com matrícula encontrada.</td>
								</tr>
							</c:otherwise>
						</c:choose>
						<tr class="even">
							<th colspan="2" style="text-align: left;"><small
								style="font-size: 0.8em;">Para visualizar as matrículas
									do aluno, clique em </small><span class="matriculasAlunoI"></span> | <small
								style="font-size: 0.8em;">Para matrícular aluno em nova
									disciplina, clique em</small><span class="novoButtonI"></span></th>
							<th colspan="3" style="text-align: right;">#{matriculaMB.alunosMatriculas.size()}
								aluno(s) com matrícula(s) cadastrados(s).</th>
						</tr>
					</tbody>
				</table>
			</h:form>
		</ui:define>
	</ui:composition>
</h:body>
</html>